<template>
	<view class="p-x-10 p-t-10">
		<view style="background: #fff" class="b-r-8 p-10">
			<my-forms ref="form" :formItem="formItem" :model="data" labelWidth="75px" :rules="rules" />
		</view>
		<view class="p-10 button">
			<button class="button-1" @click="fn">确定</button>
		</view>
	</view>
</template>

<script setup>
	import {
		messageAdd
	} from '@/api/message.js';

	const userInfo = uni.getStorageSync('userInfo');

	const data = ref({
			'264290120432238595': '["综管APP"]',
			'264290120432238592': userInfo.userNameCN,
			'264290120432238594': `${new Date().getTime()}`,
			'264290120432238597': uni.$store.user.version
		}),
		formItem = computed(() => {
			return [{
					label: '系统类型',
					prop: '264290120432238595',
					itemType: 'radio',
					placement: "column",
					list: [{
							label: '综管APP',
							value: '["综管APP"]'
						},
						{
							label: 'HSE',
							value: '["HSE"]'
						},
						{
							label: '设备全生命周期',
							value: '["设备全生命周期"]'
						},
						{
							label: '矿山设计',
							value: '["矿山设计"]'
						},
						{
							label: '人员定位',
							value: '["人员定位"]'
						}
					],
					required: true
				},
				{
					label: '意见反馈',
					prop: '264290120432238596',
					itemType: 'textarea',
					autoHeight: true,
					required: true
				},
				{
					label: '联系方式',
					prop: '264290120432238593',
					type: 'number',
					maxlength: 11,
					required: true
				}
			];
		}),
		rules = {
			'264290120432238593': {
				rules: [{
						required: true,
						errorMessage: '请输入联系方式'
					},
					{
						pattern: /^1[3-9]\d{9}$/,
						errorMessage: '联系方式格式错误'
					}
				]
			}
		};

	const form = ref(null);

	function fn() {
		form.value.$refs.refMyForm.validate().then((val) => {
			messageAdd({
				formId: '264285887125405696',
				viewId: '264285887137988608',
				data: data.value
			}).then((res) => {
				if (res.msg == 'success') {
					uni.showToast({
						icon: 'success',
						title: '提交成功'
					});
					uni.navigateBack({
						delta: 1
					});
				} else {
					uni.showToast({
						title: res.msg
					});
				}
			});
		});
	}
</script>

<style lang="scss" scoped>
	.button {
		position: fixed;
		width: 90%;
		bottom: 40rpx;
		left: 5%;

		.button-1 {
			color: #fff;
			background: linear-gradient(285deg, #24c68e 4%, #27dc9c 89%);
		}

		.button-2 {
			color: #fff;
			background: linear-gradient(285deg, #3f7efc 4%, #59a6fb 89%);
		}
	}

	:deep() {
		uni-button:after {
			border: 0;
		}
	}
</style>